package net.sk.cam;

import java.awt.image.BufferedImage;

import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.CumulativeProtocolDecoder;
import org.apache.mina.filter.codec.ProtocolDecoderOutput;


public class CtrlDecoder extends CumulativeProtocolDecoder {
    private static final String DECODER_STATE_KEY = CtrlDecoder.class.getName() + ".STATE";
    private static class DecoderState {
        boolean bHeart = false;
        long buflen = FramePara.LEN_Para;
    }

	@Override
	protected boolean doDecode(IoSession session, IoBuffer in,
			ProtocolDecoderOutput out) throws Exception {
		// TODO Auto-generated method stub
        DecoderState decoderState = (DecoderState) session.getAttribute(DECODER_STATE_KEY);
        if (decoderState == null) {
            decoderState = new DecoderState();
            session.setAttribute(DECODER_STATE_KEY, decoderState);
        }
        String str = readFrameHeader(in);
        if(str!=null){
        	out.write(str);
        	return true;
        }
        return false;
	}
    private String readFrameHeader(IoBuffer in){
    	FramePara fh = new FramePara();
    	return fh.decodePara(in);
    }

}
